package com.lxf.dao.Impl;

import com.lxf.bean.Users;
import com.lxf.dao.DBUtils;
import com.lxf.dao.UsersDao;

import java.sql.SQLException;
import java.util.ArrayList;

public class UsersDaoImpl extends DBUtils implements UsersDao {
    @Override
    public Users login(String username, String password) {
        Users users = null;
        try {

            String sql = "select * from users where loginname = ? and password = ?";
            ArrayList arrayList = new ArrayList();
            arrayList.add(username);
            arrayList.add(password);
            resultSet = query(sql,arrayList);
            if (resultSet==null){
                return null;
            }
            while (resultSet.next()) {
                users = new Users();
                users.setLoginName(resultSet.getString("loginname"));
                users.setPassword(resultSet.getString("password"));
                users.setRealName(resultSet.getString("realname"));
                users.setUserId(Integer.parseInt(resultSet.getString("userid")));
                System.out.println("数据库数据："+users.toString());
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return users;
    }
}
